package com.example.onlineeducation.mapper

import com.example.onlineeducation.data.constant.ProblemType
import com.example.onlineeducation.data.entity.OptionEntity
import com.example.onlineeducation.data.entity.PractiseQuestionEntity
import com.example.onlineeducation.data.entity.ProblemEntity
import com.example.onlineeducation.data.json.OnlineExaminationQuestionsJson
import com.example.onlineeducation.data.json.PractiseQuestionJson
import com.yc.jetpacklib.extension.ycToNoEmpty
import com.yc.jetpacklib.mapper.IMapper

class PractiseQuestionMapper : IMapper<List<PractiseQuestionJson>?, List<ProblemEntity>?> {
    override fun map(input: List<PractiseQuestionJson>?): List<ProblemEntity>? {
        return input?.map { json ->
            ProblemEntity(
                json.questionId,
                json.content.ycToNoEmpty(),
                ProblemType.toType(json.type),
                json.options?.map {
                    OptionEntity(
                        it?.id.ycToNoEmpty(""),
                        it?.content.ycToNoEmpty()
                    )
                }
            )
        }
    }
}
